#define _CRT_SECURE_NO_WARNINGS 1

#include "heap.h"

void CreatData(int count)
{
	size_t n = count;
	srand((unsigned int)time(NULL));
	//const char* file = "data.txt";
	FILE* fin = fopen("data.txt", "w");
	assert(fin);
	for (size_t i = 0; i < n; i++)
	{
		int x = rand() % 1000000;
		fprintf(fin, "%d\n", x);
	}
	fclose(fin);
}

void PrintTopK(int k)
{
	//const char* file = "data.txt";
	FILE* fout = fopen("data.txt", "r");
	assert(fout);
	int* kminheap = (int*)malloc(sizeof(int) * k);
	assert(kminheap);
	for (int i = 0; i < k; i++)
	{
		fscanf(fout, "%d", &kminheap[i]);
	}
	for (int i = (k - 1 - 1) / 2; i >= 0; i--)
	{
		AdjustDown(kminheap, k, i);
	}
	int val = 0;
	while (!feof(fout))
	{
		fscanf(fout, "%d", &val);
		if (val > kminheap[0])
		{
			kminheap[0] = val;
			AdjustDown(kminheap, k, 0);
		}
	}
	for (int i = 0; i < k; i++)
	{
		printf("%d ", kminheap[i]);
	}
	printf("\n");
	fclose(fout);
}